<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Proxy:代理</title>
    <script>
        // new Proxy(target,handler);
        // let obj=new Proxy(被代理的对象，对代理的对象做什么操作)

        // handler:
        // {
        //     set(){},//设置的时候干的事情
        //     get(){},//获取干的事情
        //     deleteProperty(){},//删除
        //     has(){},//问你有没有这个东西 'xxx' in obj
        //     apply()//调用函数处理
        //     .....
        // }
    </script>

    <script>
        let obj = {
            name: 'Strive'
        };

        let newObj = new Proxy(obj, {
            get(target, property) {
                if (property in target) {
                    console.log(`您访问了${property}`);
                    return target[property];
                } else {
                    // throw new ReferenceError(`${property}属性不在此对象上`);
                    console.warn(`${property}属性不在此对象上`);
                    return '*-*';
                }
            }
        });

        // newObj.name; //此时，property=name
        console.log(newObj.name);
        console.log(newObj.age);
        // console.log(obj.name);
    </script>
</head>

<body>

</body>

</html>